sound_pool object
This method will update the range of a sound on a 2d grid.
bool update_sound_range_2d(int slot, int left_range, int right_range, int backward_range, int forward_range)
Parameters:
slot
The slot of the sound to update.
left_range
The leftmost position from the centre of the source where the sound should remain with the listener.
right_range
The rightmost position from the centre of the source where the sound should remain with the listener.
backward_range
The backward position from the centre of the source where the sound should remain with the listener.
forward_range
The forward position from the centre of the source where the sound should remain with the listener.
Return value:
true on success, false on failure.
Remarks:
The range of the sound determines how far the listener can move before they move away from the source. This, for example, enables you to have a river or an impassable wall of fire or electricity, etc.
Please note: When dealing with sound slots, be sure that you set the persistent flag to true for all non-looping sounds when you first create them. If you fail to do this, manipulating a sound in any way by use of its slot number can have unpredictable results. This is because the sound pool automatically cleans up any sound that has finished playing and that is not set to be persistent, with the result that the slot that was returned on creation is no longer invalid and may, in the worst case scenario, refer to a completely different sound.
Example:
#include "sound_pool.bgt"
sound_pool sounds;
timer move_timer;
int x, y;
void main()
{
sounds.max_distance=70;
sounds.behind_pitch=95;
x=0;
y=0;
int slot=sounds.play_1d("sounds/loop.wav", 100, pos, true);
while(true)
{
if(move_timer.elapsed>=200)
{
move_timer.restart();
x++;
y++;
sounds.update_sound_range_2d(slot, 5, 5, 5, 5);
sounds.update_sound_2d(slot, x, y);
}
if(x>=100)
{
exit();
}
}
}